package cn.com.dashihui.pay.wx.request;

import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;

import com.jfinal.kit.PropKit;

import cn.com.dashihui.kit.CommonKit;
import cn.com.dashihui.pay.wx.kit.Signature;
/**
 * 查询支付、退款订单状态请求封装
 * @author Administrator
 *
 */
public class QueryOrderReqData {
	
	private String appid;
	private String mch_id;
	private String transaction_id;
	private String out_trade_no;
	private String nonce_str;
	private String sign;
	
    public QueryOrderReqData(String out_trade_no){
    	setAppid(PropKit.get("weixinpay.appid"));
    	setMch_id(PropKit.get("weixinpay.mch_id"));
    	setOut_trade_no(out_trade_no);
    	setNonce_str(CommonKit.getRandomStringByLength(32));
    	String sign = Signature.getSign(toMap());
    	setSign(sign);//把签名数据设置到Sign这个属性中
    }
    public QueryOrderReqData(String transaction_id, String out_trade_no){
    	setAppid(PropKit.get("weixinpay.appid"));
    	setMch_id(PropKit.get("weixinpay.mch_id"));
    	setOut_trade_no(out_trade_no);
    	setTransaction_id(transaction_id);
    	setNonce_str(CommonKit.getRandomStringByLength(32));
    	String sign = Signature.getSign(toMap());
    	setSign(sign);//把签名数据设置到Sign这个属性中
    }

	public String getAppid() {
		return appid;
	}
	public void setAppid(String appid) {
		this.appid = appid;
	}
	public String getMch_id() {
		return mch_id;
	}
	public void setMch_id(String mch_id) {
		this.mch_id = mch_id;
	}
	public String getTransaction_id() {
		return transaction_id;
	}
	public void setTransaction_id(String transaction_id) {
		this.transaction_id = transaction_id;
	}
	public String getOut_trade_no() {
		return out_trade_no;
	}
	public void setOut_trade_no(String out_trade_no) {
		this.out_trade_no = out_trade_no;
	}
	public String getNonce_str() {
		return nonce_str;
	}
	public void setNonce_str(String nonce_str) {
		this.nonce_str = nonce_str;
	}
	public String getSign() {
		return sign;
	}
	public void setSign(String sign) {
		this.sign = sign;
	}
	public Map<String,Object> toMap(){
        Map<String,Object> map = new HashMap<String, Object>();
        Field[] fields = this.getClass().getDeclaredFields();
        for (Field field : fields) {
            Object obj;
            try {
                obj = field.get(this);
                if(obj!=null){
                    map.put(field.getName(), obj);
                }
            } catch (IllegalArgumentException e) {
                e.printStackTrace();
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            }
        }
        return map;
    }
}
